import { alovaInstance } from '@/utils/request'
import { Group, CreateGroupRequest, UpdateGroupRequest, GroupListResponse } from '@/types'
import { API_PATHS, API_CONFIG } from '@/configs'

// 分组相关API

/**
 * 获取分组列表
 * @returns 分组列表
 */
export const getGroups = async () => {
  const method = alovaInstance.Get<GroupListResponse>(
    `${API_CONFIG.PREFIX}/${API_CONFIG.VERSION}${API_PATHS.GROUP.LIST}`
  )
  return await method.send()
}

/**
 * 创建分组
 * @param data 分组创建请求数据
 * @returns 创建的分组
 */
export const createGroup = async (data: CreateGroupRequest) => {
  const method = alovaInstance.Post<Group>(
    `${API_CONFIG.PREFIX}/${API_CONFIG.VERSION}${API_PATHS.GROUP.CREATE}`,
    data
  )
  return await method.send()
}

/**
 * 更新分组
 * @param id 分组ID
 * @param data 分组更新请求数据
 * @returns 更新后的分组
 */
export const updateGroup = async (id: number, data: UpdateGroupRequest) => {
  const method = alovaInstance.Put<Group>(
    `${API_CONFIG.PREFIX}/${API_CONFIG.VERSION}${API_PATHS.GROUP.UPDATE(id)}`,
    data
  )
  return await method.send()
}

/**
 * 删除分组
 * @param id 分组ID
 * @returns 删除结果
 */
export const deleteGroup = async (id: number) => {
  const method = alovaInstance.Delete(
    `${API_CONFIG.PREFIX}/${API_CONFIG.VERSION}${API_PATHS.GROUP.DELETE(id)}`
  )
  return await method.send()
}
